/**
 * Copyright (C) 2011-2012 GreenSoft S.A.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *        http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ar.com.greensoft.neosystem.user;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.ManagedBean;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;

import ar.com.greensoft.jeecommons.web.jsf.export.ColumnValueMapper;
import ar.com.greensoft.jeecommons.web.jsf.export.ExportColInfo;
import ar.com.greensoft.jeecommons.web.jsf.export.impl.ExportColInfoImpl;
import ar.com.greensoft.neosystem.dao.GenericDao;
import ar.com.greensoft.neosystem.dao.PaisDao;
import ar.com.greensoft.neosystem.model.address.Pais;
import ar.com.greensoft.neosystem.search.SearchFilter;
import ar.com.greensoft.neosystem.search.TextSearchFilter;

/**
 *
 * @author Jorge E. Villaverde
 * @since 1.0.0
 * @version 1.0.0
 */
@ManagedBean
@SessionScoped
@Named
public class PaisBean extends AbstractLongIdUserRoleCrudFacedeBean<Pais>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 461612882541641612L;
	private static final String ENTITY_PREFIX = "direccion/pais";
	private static final String ENTITY_MSG_PREFIX = "direccionPais";

	@Inject
	private PaisDao dao;
	
	@Override
	protected GenericDao<Pais, Long> getDao() {
		return dao;
	}

	@Override
	protected Pais newEntity() {
		return new Pais();
	}

	@Override
	protected String entityPrefix() {
		return ENTITY_PREFIX;
	}

	@Override
	protected String getEntityMessagePrefix(){
		return ENTITY_MSG_PREFIX;
	}
	
	@Override
	protected SearchFilter createSearchFilter() {
		return new TextSearchFilter();
	}

	@Override
	protected String getEntityName(Pais entity) {
		return entity.getName();
	}

	@Override
	protected Pais findEntityByName(String entityName) {
		return dao.findByName(entityName);
	}

	@Override
	protected List<ExportColInfo> getExportColInfoList() {
		List<ExportColInfo> ret = new ArrayList<ExportColInfo>();
		ret.add(new ExportColInfoImpl(0, "paisNombre"));
		ret.add(new ExportColInfoImpl(0, "paisCodigISO"));
		return ret;
	}

	@Override
	protected ColumnValueMapper<Pais> getColumnValueMapper() {
		return new ColumnValueMapper<Pais>() {
			@Override
			public String getColumnValue(int columnNumber, Pais value) {
				switch (columnNumber) {
				case 0:
					return value.getName();
				case 1:
					return value.getCodigoISO().toString();
				default:
					break;
				}
				return "";
			}
		};
	}
}
